import 'package:flutter/material.dart';
import 'package:furniture_demo/components/title_text.dart';
import 'package:furniture_demo/constants.dart';
import 'package:furniture_demo/models/Categories.dart';
import 'package:furniture_demo/models/Product.dart';
import 'package:furniture_demo/screen/home/components/product_card.dart';
import 'package:furniture_demo/screen/home/components/recommend_products.dart';
import 'package:furniture_demo/services/fetchCategories.dart';
import 'package:furniture_demo/services/fetchProducts.dart';
import 'package:furniture_demo/size_config.dart';

import 'categories.dart';

class HomeBody extends StatelessWidget {
  const HomeBody({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double defaultSize = SizeConfig.defaultSize;
    return SingleChildScrollView(
      child: SafeArea(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Padding(
              padding: EdgeInsets.all(defaultSize * 2),
              child: TitleText(title: 'Browse by Categorys'),
            ),
            FutureBuilder(
              future: fetchCategories(),
              builder: (ctx, snapshop) => snapshop.hasData
                  ? Categories(categories: (snapshop.data) as List<Category>)
                  : Center(child: Image.asset("assets/ripple.gif")),
            ),
            Divider(height: 5),
            Padding(
              padding: EdgeInsets.all(defaultSize),
              child: TitleText(title: 'Recommends For You'),
            ),
            FutureBuilder(
                future: fetchProducts(),
                builder: (context, snapshot) {
                  return snapshot.hasData
                      ? RecommendProducts(
                          products: (snapshot.data) as List<Product>,
                        )
                      : Center(child: Image.asset("assets/ripple.gif"));
                })
          ],
        ),
      ),
    );
  }
}
